<?php
/* 
 * This Factory istantiates the BusinessObjects
 * and add adapters (observers) to the object
 * adapete can be relative to persistency or to ifferent services
 *
 */

class BusinessFactory
{
    /**
     * Facotry method, get the class name and the list of adapter to
     * istatiate an object
     * 
     * @param <type> $class
     * @param <type> $adapters
     * @return <type>
     */
    static function getObject($class, $adapters = array()){
        if(!is_array($adapters)){
            $adapters = array($adapters);
        }

        $object = new $class();

        foreach($adapters as $name){
            /*
             * we pass the object to the $adapters cause he may
             * need to set some internal variable from the object state
             */
            $adapter = new $name($object);
            $object->addAdapter($adapter);
        }
        return $object;
    }
}
